package com.xckj.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.adrninistrator.jacg.common.enums.OtherConfigFileUseSetEnum;
import com.adrninistrator.jacg.util.JACGFileUtil;
import com.adrninistrator.jacg.util.JACGUtil;
import com.xckj.entity.MethodClass4callee;
import com.xckj.entity.MethodClass4caller;
import com.xckj.service.ClassMethodService;
import com.xckj.service.MethodClass4calleeService;
import com.xckj.utils.ReturnT;

/**
 * @description 工程中的所有的方法和接口
 * @author yanchf
 * @date 2023-12-09
 */
@Service
public class ClassMethodServiceImpl implements ClassMethodService {
	@Value("${app.project.name}")
	public String appName;


	@Override
	public Object insert(MethodClass4callee methodClass4callee) {

		// valid
		if (methodClass4callee == null) {
			return ReturnT.error("必要参数缺失");
        }

        return ReturnT.success();
	}


	@Override
	public Object delete(int id) {
		return ReturnT.success();
	}


	@Override
	public Object update(MethodClass4callee methodClass4callee) {
		return ReturnT.success();
	}


	@Override
	public MethodClass4callee load(int id) {
		return null;
	}


	@Override
	public Map<String,Object> pageList(int offset, int pagesize) {
	   	String confFile = OtherConfigFileUseSetEnum.OCFUSE_METHOD_CLASS_4CALLEE.getKey();
    	Set<String> configSet = JACGFileUtil.readFile2Set(JACGUtil.getInputRootPath() + confFile);
		List<MethodClass4callee> pageList = new ArrayList<MethodClass4callee>();
		int totalCount = 0;
    	for(String conf : configSet) {
    		MethodClass4callee allowedClassPre = new MethodClass4callee();
			allowedClassPre.setAppName(appName);
			allowedClassPre.setMethod(conf);
			pageList.add(allowedClassPre);
		}

		// result
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("pageList", pageList);
		result.put("totalCount", totalCount);
		return ReturnT.success(result);
	}

}